<?php
$csvfile = "tbkonzulok.csv";
$outputfile = "tbkonzulok.sql";
$startindex = 1;

/***********************************************/
function processRow($counter, $rowdata, $out) {
    $country = $rowdata[0];
    $city = $rowdata[1];
    $name = $rowdata[2];
    $email = $rowdata[4];

    $insert1 = "INSERT INTO lst_tbkonzulok (country, city, name, email) ".
              "VALUES ('$country', '$city', '$name', '$email');\r\n";
    fputs($out, $insert1);
}
/***********************************************/

$f = fopen($csvfile, "r");
$c = 0;
$out = fopen($outputfile,  "w");
$counter = $startindex;
while (!feof($f)) {
    $c++;
    $row = rtrim(fgets($f));
    if ($c == 1) { continue; }
    $row = str_replace("\"", "", $row);
    $row = str_replace("'", "''", $row);
    $rowdata = explode(";", $row);
    processRow($counter, $rowdata, $out);
    $counter++;
}
fclose($f);
fclose($out);
?>
